<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('授信记录') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('债务人')" prop="debtor">
        <el-input
          v-model="queryParams.debtor"
          :placeholder="$t('债务人')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item :label="$t('债券一级类别')" prop="bondPrimaryClass">
        <el-select v-model="queryParams.bondPrimaryClass" :placeholder="$t('债券一级类别')" @change="bondPrimary">
          <el-option
            v-for="item in bondPrimaryClassOptions"
            :key="item.dictValue"
            :value="item.dictValue"
            :label="item.dictLabel"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('债券二级类别')" prop="bondSecondaryClassSingleValue">
        <dict-select
          v-if="showBondSencodStatus"
          v-model="queryParams.bondSecondaryClassSingleValue"
          :dictionary="'deal_bond_NW_' + queryParams.bondPrimaryClass"
          :placeholder="$t('债券二级类别')"
          clearable
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dealBondCreditList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('债券一级类别')" align="center" prop="bondPrimaryClass" :formatter="bondPrimaryClassFormat" />
      <el-table-column :label="$t('债券二级类别')" align="center" prop="bondSecondaryClassLabel" show-overflow-tooltip />
      <el-table-column :label="$t('授信额度')" align="center" prop="creditLine" show-overflow-tooltip>
        <template v-slot="scope">
          <span>{{ moneyFormat(scope.row.creditLine, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('授信截止日期')" align="center" prop="creditDeadline" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.creditDeadline) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请人')" align="center" prop="createBy.nickName" show-overflow-tooltip />
      <el-table-column :label="$t('申请时间')" align="center" prop="createTime" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.creditDeadline) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('审批状态')" align="center" width="120">
        <template slot-scope="scope">
          <ProcessStatus :status="scope.row.actStatus" :act-id="scope.row.actId" />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { delDealBondCredit, exportDealBondCredit, listDealBondCredit } from '@/api/bond/credit/dealBondCredit'

export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 授信信息表格数据
      dealBondCreditList: [],
      // 弹出层标题
      title: '授信记录',
      // 是否显示弹出层
      formOpen: false,
      // 债券一级类别字典
      bondPrimaryClassOptions: [],

      // 债券二级类别字典
      bondSecondaryClassMap: {},
      showBondSencodStatus: true,
      // 查询参数
      queryParams: {
        debtor: undefined,
        bondPrimaryClass: undefined,
        bondSecondaryClassSingleValue: undefined,
        bondId: this.$route.query.id,
        record: true,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      disabled: false
    }
  },
  created() {
    this.getList()
    this.getDicts('deal_bond_NW').then(response => {
      this.bondPrimaryClassOptions = response.data
    })
  },
  methods: {
    /** 查询授信信息列表 */
    getList() {
      this.loading = true
      listDealBondCredit(this.queryParams).then(response => {
        this.dealBondCreditList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 债券一级类别字典翻译
    bondPrimaryClassFormat(row) {
      return this.selectDictLabel(this.bondPrimaryClassOptions, row.bondPrimaryClass)
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,

        debtor: undefined,

        bondPrimaryClass: undefined,

        bondSecondaryClass: undefined,

        creditLine: undefined,

        creditDeadline: undefined,

        record: undefined,

        remark: undefined

      }
      this.resetForm('form')
    },
    bondPrimary() {
      this.showBondSencodStatus = false
      this.queryParams.bondSecondaryClassSingleValue = undefined
      this.$nextTick(() => {
        this.showBondSencodStatus = true
      })
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.dealBondCreditForm.init(null)
      })
    },
    /** 修改按钮操作 */
    updateHandle(row, isChange) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.dealBondCreditForm.init(row, isChange)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return delDealBondCredit(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    },
    /** 导出按钮操作 */
    exportHandle() {
      const queryParams = this.queryParams
      this.$confirm(this.$t('是否确认导出数据项?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return exportDealBondCredit(queryParams)
      }).then(response => {
        this.download(response.msg)
      }).catch(function() {
      })
    }
  }
}
</script>

<style scoped>

</style>
